//
//  LadingCarInfoView.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/9/14.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "LadingCarInfoView.h"

@interface LadingCarInfoView ()

@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *carNumLab;
@property (nonatomic, strong) UIButton *listBtn;
@property (nonatomic, strong) UILabel *listLab;
@property (nonatomic, strong) UILabel *lineLab;
@property (nonatomic, strong) LadingCarInfoTimeLineView *sureView;
@property (nonatomic, strong) LadingCarInfoTimeLineView *chuFaView;
@property (nonatomic, strong) LadingCarInfoTimeLineView *daoDaView;
@property (nonatomic, strong) LadingCarInfoTimeLineView *zhuangCheView;
@property (nonatomic, strong) LadingCarInfoTimeLineView *wanChengView;

@end

@implementation LadingCarInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20, frame.size.width * 0.5, 17)];
        self.nameLab.font = BoldFontOfSize(16);
        self.nameLab.textColor = HexColor(0x2B2C44);
        [self addSubview:self.nameLab];
        
        self.carNumLab = [[UILabel alloc] initWithFrame:CGRectMake(15, self.nameLab.nim_bottom + 5, frame.size.width * 0.5, 15)];
        self.carNumLab.font = [UIFont systemFontOfSize:14];
        self.carNumLab.textColor = HexColor(0x9C9DB3);
        [self addSubview:self.carNumLab];
        
        self.lineLab = [[UILabel alloc] initWithFrame:CGRectMake(15, self.carNumLab.nim_bottom + 15, frame.size.width - 30, 1)];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self addSubview:self.lineLab];
        
        self.listBtn = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width - 30 - 30, (self.lineLab.nim_top - 30 - 5 - 13) * 0.5, 30, 30)];
        [self.listBtn setImage:[UIImage imageNamed:@"icon_map_list_btn"] forState:0];
        [self.listBtn addTarget:self action:@selector(listClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.listBtn];
        
        self.listLab = [UILabel new];
        self.listLab.font = [UIFont systemFontOfSize:12];
        self.listLab.textColor = HexColor(0x585974);
        self.listLab.text = @"装车清单";
        [self.listLab sizeToFit];
        self.listLab.nim_top = self.listBtn.nim_bottom + 5;
        self.listLab.nim_centerX = self.listBtn.nim_centerX;
        [self addSubview:self.listLab];
        
        CGFloat margin = (frame.size.height - self.lineLab.nim_bottom - 30 * 5) * 0.5;
        
        self.sureView = [[LadingCarInfoTimeLineView alloc] initWithFrame:CGRectMake(self.lineLab.nim_left, self.lineLab.nim_bottom + margin, self.lineLab.nim_width, 30)];
        [self addSubview:self.sureView];
        
        self.chuFaView = [[LadingCarInfoTimeLineView alloc] initWithFrame:CGRectMake(self.lineLab.nim_left, self.sureView.nim_bottom, self.lineLab.nim_width, self.sureView.nim_height)];
        [self addSubview:self.chuFaView];
        
        self.daoDaView = [[LadingCarInfoTimeLineView alloc] initWithFrame:CGRectMake(self.lineLab.nim_left, self.chuFaView.nim_bottom, self.lineLab.nim_width, self.sureView.nim_height)];
        [self addSubview:self.daoDaView];
        
        self.zhuangCheView = [[LadingCarInfoTimeLineView alloc] initWithFrame:CGRectMake(self.lineLab.nim_left, self.daoDaView.nim_bottom, self.lineLab.nim_width, self.sureView.nim_height)];
        [self addSubview:self.zhuangCheView];
        
        self.wanChengView = [[LadingCarInfoTimeLineView alloc] initWithFrame:CGRectMake(self.lineLab.nim_left, self.zhuangCheView.nim_bottom, self.lineLab.nim_width, self.sureView.nim_height)];
        [self addSubview:self.wanChengView];
        
    }
    return self;
}

- (void)listClick {
    if (self.listBlock) {
        self.listBlock();
    }
}

-(void)setModel:(LadingCarMapInfoModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.nameLab.text = self.model.name;
    self.carNumLab.text = self.model.num;
    
    self.sureView.title = @"确认";
    self.sureView.time = self.model.acceptTime;
    self.sureView.isFirst = YES;
    self.sureView.isLast = NO;
    if ([self.model.status isEqualToString:@"1"]) {
        self.sureView.isSelected = YES;
    }else {
        self.sureView.isSelected = NO;
    }
    
    self.chuFaView.title = @"出发";
    self.chuFaView.time = self.model.setoutTime;
    self.chuFaView.isFirst = NO;
    self.chuFaView.isLast = NO;
    if ([self.model.status isEqualToString:@"4"]) {
        self.chuFaView.isSelected = YES;
    }else {
        self.chuFaView.isSelected = NO;
    }
    
    self.daoDaView.title = @"到达";
    self.daoDaView.time = self.model.arriveTime;
    self.daoDaView.isFirst = NO;
    self.daoDaView.isLast = NO;
    if ([self.model.status isEqualToString:@"5"]) {
        self.daoDaView.isSelected = YES;
    }else {
        self.daoDaView.isSelected = NO;
    }
    
    self.zhuangCheView.title = @"装车";
    self.zhuangCheView.time = self.model.loadingTime;
    self.zhuangCheView.isFirst = NO;
    self.zhuangCheView.isLast = NO;
    if ([self.model.status isEqualToString:@"6"]) {
        self.zhuangCheView.isSelected = YES;
    }else {
        self.zhuangCheView.isSelected = NO;
    }
    
    self.wanChengView.title = @"完成";
    self.wanChengView.time = self.model.finishTime;
    self.wanChengView.isFirst = NO;
    self.wanChengView.isLast = YES;
    if ([self.model.status isEqualToString:@"9"]) {
        self.wanChengView.isSelected = YES;
    }else {
        self.wanChengView.isSelected = NO;
    }
    
}

@end

@interface LadingCarInfoTimeLineView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *topLine;
@property (nonatomic, strong) UILabel *botLine;
@property (nonatomic, strong) UILabel *midDot;
@property (nonatomic, strong) UIImageView *selectImgView;

@end

@implementation LadingCarInfoTimeLineView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 7.5, 75, 15)];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x9C9DB3);
        [self addSubview:self.titleLab];
        
        self.midDot = [UILabel new];
        self.midDot.nim_width = 10;
        self.midDot.nim_height = 10;
        self.midDot.nim_left = self.titleLab.nim_right + 7;
        self.midDot.nim_centerY = self.titleLab.nim_centerY;
        self.midDot.layer.masksToBounds = YES;
        self.midDot.layer.cornerRadius = 5;
        self.midDot.backgroundColor = HexColor(0x9C9DB3);
        [self addSubview:self.midDot];
        
        self.topLine = [UILabel new];
        self.topLine.backgroundColor = HexColor(0x9C9DB3);
        self.topLine.nim_top = 0;
        self.topLine.nim_width = 2;
        self.topLine.nim_centerX = self.midDot.nim_centerX;
        self.topLine.nim_height = self.midDot.nim_top - 2;
        [self addSubview:self.topLine];
        
        self.botLine = [UILabel new];
        self.botLine.backgroundColor = HexColor(0x9C9DB3);
        self.botLine.nim_top = self.midDot.nim_bottom + 2;
        self.botLine.nim_width = 2;
        self.botLine.nim_centerX = self.midDot.nim_centerX;
        self.botLine.nim_height = frame.size.height - self.botLine.nim_top;
        [self addSubview:self.botLine];
        
        self.timeLab = [[UILabel alloc] initWithFrame:CGRectMake(20 + self.midDot.nim_right, 7.5, frame.size.width - (20 + self.midDot.nim_right), 15)];
        self.timeLab.textAlignment = NSTextAlignmentLeft;
        self.timeLab.font = [UIFont systemFontOfSize:14];
        self.timeLab.textColor = HexColor(0x9C9DB3);
        [self addSubview:self.timeLab];
        
        self.selectImgView = [UIImageView new];
        self.selectImgView.nim_width = 24;
        self.selectImgView.nim_height = 24;
        self.selectImgView.nim_centerX = self.midDot.nim_centerX;
        self.selectImgView.nim_centerY = self.midDot.nim_centerY;
        self.selectImgView.image = [UIImage imageNamed:@"icon_map_car_status_selected"];
        self.selectImgView.hidden = YES;
        [self addSubview:self.selectImgView];
    }
    return self;
}

-(void)setTitle:(NSString *)title {
    _title = title;
    self.titleLab.text = title;
}

-(void)setTime:(NSString *)time {
    _time = time;
    self.timeLab.text = time;
}

-(void)setIsFirst:(BOOL)isFirst {
    _isFirst = isFirst;
    self.topLine.hidden = isFirst;
}

-(void)setIsLast:(BOOL)isLast {
    _isLast = isLast;
    self.botLine.hidden = isLast;
}

-(void)setIsSelected:(BOOL)isSelected {
    _isSelected = isSelected;
    self.selectImgView.hidden = !isSelected;
    if (isSelected) {
        self.titleLab.nim_height = 19;
        self.titleLab.nim_centerY = self.selectImgView.nim_centerY;
        self.titleLab.font = BoldFontOfSize(18);
        self.titleLab.textColor = HexColor(0x3D68EB);
        
        self.timeLab.nim_height = 19;
        self.timeLab.nim_centerY = self.selectImgView.nim_centerY;
        self.timeLab.font = BoldFontOfSize(18);
        self.timeLab.textColor = HexColor(0x2B2C44);
    }else {
        self.titleLab.nim_height = 15;
        self.titleLab.nim_centerY = self.midDot.nim_centerY;
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x9C9DB3);
        
        self.timeLab.nim_height = 15;
        self.timeLab.nim_centerY = self.midDot.nim_centerY;
        self.timeLab.font = [UIFont systemFontOfSize:14];
        self.timeLab.textColor = HexColor(0x9C9DB3);
    }
}

@end
